package com.base.hsm.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.common.annotation.RepeatSubmit;
import com.base.common.annotation.Log;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.common.utils.poi.ExcelUtil;
import com.base.hsm.domain.vo.TSysHsmVo;
import com.base.hsm.domain.bo.TSysHsmBo;
import com.base.hsm.service.ITSysHsmService;
import com.base.common.core.page.TableDataInfo;

/**
 * 密码机信息
 *
 * @author base
 * @date 2023-10-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hsm/sysHsm")
public class TSysHsmController extends BaseController {

    private final ITSysHsmService iTSysHsmService;

    /**
     * 查询密码机信息列表
     */
// @SaCheckPermission("hsm:sysHsm:list")
    @GetMapping("/list")
    public R<TableDataInfo<TSysHsmVo>> list(TSysHsmBo bo, PageQuery pageQuery) {
        return R.ok(iTSysHsmService.queryPageList(bo, pageQuery));
    }

    /**
     * 导出密码机信息列表
     */
    //   @SaCheckPermission("hsm:sysHsm:export")
    @Log(title = "密码机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TSysHsmBo bo, HttpServletResponse response) {
        List<TSysHsmVo> list = iTSysHsmService.queryList(bo);
        ExcelUtil.exportExcel(list, "密码机信息", TSysHsmVo.class, response);
    }

    /**
     * 获取密码机信息详细信息
     *
     * @param hsmId 主键
     */
    //    @SaCheckPermission("hsm:sysHsm:query")
    @GetMapping("/{hsmId}")
    public R<TSysHsmVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String hsmId) {
        return R.ok(iTSysHsmService.queryById(hsmId));
    }

    /**
     * 新增密码机信息
     */
//     @SaCheckPermission("hsm:sysHsm:add")
    @Log(title = "密码机信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TSysHsmBo bo) {
        return toAjax(iTSysHsmService.insertByBo(bo));
    }

    /**
     * 修改密码机信息
     */
    //   @SaCheckPermission("hsm:sysHsm:edit")
    @Log(title = "密码机信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TSysHsmBo bo) {
        return toAjax(iTSysHsmService.updateByBo(bo));
    }

    /**
     * 删除密码机信息
     *
     * @param hsmIds 主键串
     */
    //  @SaCheckPermission("hsm:sysHsm:remove")
    @Log(title = "密码机信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{hsmIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] hsmIds) {
        return toAjax(iTSysHsmService.deleteWithValidByIds(Arrays.asList(hsmIds), true));
    }
}
